package cn.maxhou.service.impl;

import cn.maxhou.entity.Supplier;
import cn.maxhou.mapper.SupplierMapper;
import cn.maxhou.service.Supplierervice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service("supplierervice2")
public class SuppliererviceImpl3 implements Supplierervice {

    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> selectAll() {
        return supplierMapper.selectAll();
    }

    @Override
    public List<Supplier> selectBySupName(String supName) {
        return supplierMapper.selectBySupName(supName);
    }

    @Override
    public int saveBatch(List<Supplier> suppliers) {
        int row = 0;
        for (int i = 0; i < suppliers.size(); i++) {
            Supplier supplier = suppliers.get(i);
            row = supplierMapper.insert(supplier);
        }
        return row;
    }

    @Transactional
    @Override
    public int deleteById(Integer id) {
        return supplierMapper.deleteById(id);
    }

    @Transactional
    @Override
    public int update(Supplier supplier) {
        return supplierMapper.update(supplier);
    }

    public void setSupplierMapper(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }
}
